package cn.service.impl;

import cn.entity.SysOffice;
import cn.mapper.SysOfficeMapper;
import cn.service.SysOfficeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional//开启事务
@CacheConfig(cacheNames = "officeCache")
public class SysOfficeServiceImpl extends BaseServiceImpl<SysOffice> implements SysOfficeService {

    @Autowired
    SysOfficeMapper sysOfficeMapper;
    @Cacheable(key = "'SysOfficeServiceImpl.selectByPrimaryKey.o:'+#obj")
    @Override
    public SysOffice selectByPrimaryKey(Object obj){
        return super.selectByPrimaryKey(obj);
    }

    @Override
    public PageInfo<SysOffice> selectPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        SysOffice sysOffice = new SysOffice();
        sysOffice.setDelFlag("0");
        return new PageInfo<SysOffice>(mapper.select(sysOffice));
    }

    @Override
    public PageInfo<SysOffice> selectPageByOfficeName(int pageNum, int pageSize, String officeName) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<SysOffice>(sysOfficeMapper.selectPageByOfficeName(officeName));
    }
}
